package com.ck.demo.service.impl;

import com.ck.demo.dao.EmpDao;
import com.ck.demo.entity.Emp;
import com.ck.demo.service.EmpService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Resource
    EmpDao empDao;
    @Override
    public List<Emp> list() {
        return empDao.list();
    }

    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int addEmp(Emp emp) {
        //设置修改的时间
        emp.setUpdate_time(new Date());
        return empDao.addEmp(emp);
    }

    @Override
    public Emp queryById(Integer id) {
        return empDao.queryById(id);
    }

    @Override
    public int updateEmp(Emp emp) {
        emp.setUpdate_time(new Date());
        emp.setEstatus(0);
        return empDao.updateEmp(emp);
    }
}
